'''
Created on 2014-03-01

@author: YoYo
'''
if __name__ == '__main__':  
    import socket  
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
    sock.bind(('localhost', 8001))  
    sock.listen(5)  
    while True:  
        connection,address = sock.accept()  
        try:  
            connection.settimeout(5)  
            buf = connection.recv(1024)  
            if buf == b'1':  
                connection.send('welcome to server!'.encode())  
            else:  
                connection.send('please go out!'.encode())  
        except socket.timeout:  
            print('time out'.encode('uft-8'))  
        connection.close()  